package cn.cloud.all.security.oauth2.provider.client;

import cn.cloud.all.security.oauth2.provider.ClientDetails;
import cn.cloud.all.security.oauth2.provider.ClientDetailsService;
import cn.cloud.all.security.oauth2.provider.ClientRegistrationException;
import cn.cloud.all.security.oauth2.provider.NoSuchClientException;

import java.util.HashMap;
import java.util.Map;

public class InMemoryClientDetailsService implements ClientDetailsService {

    private Map<String, ClientDetails> clientDetailsStore = new HashMap<>();

    public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
        ClientDetails details = clientDetailsStore.get(clientId);
        if (details == null) {
            throw new NoSuchClientException("No client with requested id: " + clientId);
        }
        return details;
    }

    public void setClientDetailsStore(Map<String, ? extends ClientDetails> clientDetailsStore) {
        this.clientDetailsStore = new HashMap<>(clientDetailsStore);
    }
}